/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class ChucnangDAL : SqlProvider<ChucnangEntity>
    {
        static ChucnangDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                ChucnangEntity entity = new ChucnangEntity();
				entity.PK_iChucnangID = Int32.Parse("0"+dr["PK_iChucnangID"].ToString());
				entity.sTenchucnang = dr["sTenchucnang"].ToString();
				entity.sKyhieu = dr["sKyhieu"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static ChucnangEntity GetOne(Int32 PK_iChucnangID)
        {
            string cmdName = "spChucnang_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iChucnangID", PK_iChucnangID);
            ChucnangEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<ChucnangEntity> GetAll()
        {
            string cmdName = "spChucnang_Get";
            return GetList(cmdName);
        }
        
        public static int Add(ChucnangEntity entity)
        {
            string cmdName = "spChucnang_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(ChucnangEntity entity)
        {
            string cmdName = "spChucnang_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int32 PK_iChucnangID)
        {
            string cmdName = "spChucnang_Delete";
            SqlParameter p = new SqlParameter("@PK_iChucnangID", PK_iChucnangID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(ChucnangEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iChucnangID", entity.PK_iChucnangID);
			p[1] = new SqlParameter("@sTenchucnang", entity.sTenchucnang);
			p[2] = new SqlParameter("@sKyhieu", entity.sKyhieu);
			p[3] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}